import numpy as np
from matplotlib import pyplot as plt
from sklearn.linear_model import LinearRegression

# 构造数据：房屋面积与价格
X = np.array([[50], [80], [100], [120]])  # 房屋面积
y = np.array([[50000], [70000], [90000], [110000]])  # 价格
# 训练模型
model = LinearRegression()
model.fit(X, y)
print("模型系数：", model.coef_)
print("模型截距：", model.intercept_)
print(f"模型预测：{model.predict([[321]])}")
# 可视化
plt.scatter(X, y)
plt.plot(X, model.predict(X))
plt.show()
